<?php
/**
 * Affiliate 后台管理控制器的基类
 */

class AController extends Controller {
	public $layout = '//layouts/column2';
	
	public $mainMenu = array();
	
	public $menu = array();
	
	public $popMenu = array();
	
	public function __construct($id, $module=null) {
		parent::__construct($id, $module);
		
		$this->mainMenu = array(
			array('label' => '网站首页', 'url' => array('/site/index')),
			array('label' => 'Affiliate 后台管理', 'url' => array('/admin/owner')),
			array('label' => '退出', 'url' => array('/site/logout'))
		);
		
		$userNum = User::getNumByAccept('P');
		$userNum = ($userNum>0)? " ($userNum)" : "";
		
		$orderNum = FirstOrder::getNumToVerify();
		$orderNum = ($orderNum>0)? " ($orderNum)" : "";
		
		$paymentRequestNum = PaymentRequest::getUnpaidNum();
		$paymentRequestNum = ($paymentRequestNum)? " ($paymentRequestNum)" : "";
		
		$this->menu = array(
			array(
				'label'=>'加盟账号管理', 
				'url'=>array('owner/list'),
				'items' => array(
					array( 'label' => '待审核账号', 'url' => array('owner/list', 'inuse' => '0') ),
					array( 'label' => '已通过账号', 'url' => array('owner/list', 'inuse' => '1')),
				)
			),
			array(
				'label'=>'激活会员管理', 
				'url'=>array('user/list'),
				'items' => array(
					array('label'=>'待审核会员'.$userNum, 'url'=>array('user/list', 'accept' => 'P')),
					array('label'=>'已审核会员-已认可', 'url'=>array('user/list', 'accept' => 'Y')),
					array('label'=>'已审核会员-已否决', 'url'=>array('user/list', 'accept' => 'N')),
				)
			),
			/*
			array(
				'label'=>'订单管理', 
				'url'=>array('order/list'),
				'items' => array(
					array('label'=>'全部订单', 'url'=>array('order/list')),
					array('label'=>'首次订单', 'url'=>array('order/listFirst'),
						'items' => array(
							array('label' => '待审核订单'.$orderNum, 'url' => array('order/listFirst', 'verify_status' => 0)),
							array('label' => '有效订单', 'url' => array('order/listFirst', 'verify_status' => 1)),
							array('label' => '无效订单', 'url' => array('order/listFirst', 'verify_status' => -1)),
						) 
					),
				)
			),
			*/
			array('label'=>'首次订单列表', 'url'=>array('order/listFirst'),
				'items' => array(
					array('label' => '待审核订单'.$orderNum, 'url' => array('order/listFirst', 'verify_status' => 0)),
					array('label' => '有效订单', 'url' => array('order/listFirst', 'verify_status' => 1)),
					array('label' => '无效订单', 'url' => array('order/listFirst', 'verify_status' => -1)),
				) 
			),
			array(
				'label'=>'付款管理', 
				'url'=>array('pay/index'),
				'items' => array(
					array('label'=>'生成月报表', 'url'=>array('payment/generateMonthReport')),
					array('label'=>'报表清单', 'url'=>array('payment/monthReportList')),
					array('label'=>'应付统计', 'url'=>array('payment/toPayList')),
					array('label'=>'付款请求'.$paymentRequestNum, 'url'=>array('payment/request')),
					array('label'=>'付款历史', 'url'=>array('payment/history')),
				)
			),
			array(
				'label' => '广告管理',
				'url' => array('adv'),
				'items' => array(
					array('label'=>'回报分析', 'url'=>array('report/return')),
					array('label'=>'流量分析', 'url'=>array('report/click')),
					array('label' => '网站管理', 'url' => array('/admin/website')),
					array('label' => '文字广告', 'url' => array('/admin/adv', 'type' => 'text')),
					array('label' => 'Banner广告', 'url' => array('/admin/adv', 'type' => 'banner')),
					array('label' => '协助建站(未可用)', 'url' => '#')
				)
			)
		);
	} 
	
	public function getPopMenu() {
		if (!empty($_GET['owner_id'])) {
			$this->popMenu = array(
				array('label' => '账号信息', 'url' => array('owner/edit', 'owner_id' => $_GET['owner_id'])),
				array('label' => '总览', 'url' => array('report/summary', 'owner_id' => $_GET['owner_id'])),
				array('label' => '每日统计', 'url' => array('report/diaryLog', 'owner_id' => $_GET['owner_id'])),
				array('label' => '会员订单', 'url' => array('order/ownerList', 'owner_id' => $_GET['owner_id'])),
				array('label' => '首次订单', 'url' => array('order/ownerListFirst', 'owner_id' => $_GET['owner_id'])),
				array('label' => '会员注册', 'url' => array('user/ownerList', 'owner_id' => $_GET['owner_id']))
			);
		}
	}
	
	public function render($name, $data=array()) {
		$this->getPopMenu();
		parent::render($name, $data);
	}
}
